#include "mainwindow.h"
#include "ui_mainwindow.h"

#include <QUrl>
#include <QNetworkProxy>

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    ui->centralWidget->setLayout(ui->verticalLayout);
    connect(ui->pushButton, SIGNAL(clicked()), this, SLOT(updateWebViewAddress()));
    /*createWidgets();*/
    QNetworkProxy proxy;
    proxy.setType(QNetworkProxy::HttpProxy);
    proxy.setHostName("proxy");
    proxy.setPort(8080);
    QNetworkProxy::setApplicationProxy(proxy);
    ui->webView->settings()->setAttribute(QWebSettings::AutoLoadImages, true);
    ui->webView->settings()->setAttribute(QWebSettings::DnsPrefetchEnabled, true);
    ui->webView->settings()->setAttribute(QWebSettings::JavascriptEnabled, true);
    ui->webView->settings()->setAttribute( QWebSettings::JavaEnabled, true);
    ui->webView->settings()->setAttribute(QWebSettings::PluginsEnabled, true);
    ui->webView->settings()->setAttribute(QWebSettings::PrivateBrowsingEnabled, true);
    ui->webView->settings()->setAttribute(QWebSettings::JavascriptCanOpenWindows, true);
    ui->webView->settings()->setAttribute(QWebSettings::JavascriptCanAccessClipboard, true);
    ui->webView->settings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, true);
    ui->webView->settings()->setAttribute(QWebSettings::LinksIncludedInFocusChain, true);
    ui->webView->settings()->setAttribute(QWebSettings::ZoomTextOnly, true);
    ui->webView->settings()->setAttribute(QWebSettings::PrintElementBackgrounds, true);
    ui->webView->settings()->setAttribute(QWebSettings::OfflineStorageDatabaseEnabled, true);
    ui->webView->settings()->setAttribute(QWebSettings::OfflineWebApplicationCacheEnabled, true);
    ui->webView->settings()->setAttribute(QWebSettings::LocalStorageEnabled, true);
    ui->webView->settings()->setAttribute(QWebSettings::LocalStorageDatabaseEnabled, true);
    ui->webView->settings()->setAttribute(QWebSettings::LocalContentCanAccessRemoteUrls, true);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::changeEvent(QEvent *e)
{
    QMainWindow::changeEvent(e);
    switch (e->type()) {
    case QEvent::LanguageChange:
        ui->retranslateUi(this);
        break;
    default:
        break;
    }
}

void MainWindow::updateWebViewAddress() {
    ui->webView->setUrl(QUrl("http://www.google.com"));
    ui->webView->load(QUrl(ui->lineEdit->text()));
}
